package com.yanqu.road.server.manger.secretVolume;

import com.yanqu.road.entity.player.UserSecretVolume;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 宴会
 */
public class SecretVolumeMgr extends TempMgr {


    @Override
    public boolean init() throws Exception {
        return reload();
    }

    public boolean save() {
        return true;
    }

    @Override
    public boolean stop() {
        return false;
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    public static int getFirstNoDate(){
        List<Integer> dateList = StringUtils.stringToIntegerList(GameConfig.SECRET_VOLUME_DATE,";");
        return dateList.get(0);
    }

    public static int getNoDate(int no){
        List<Integer> dateList = StringUtils.stringToIntegerList(GameConfig.SECRET_VOLUME_DATE,";");
        if(dateList.size() >= no){
            return dateList.get(no - 1);
        }
        return 0;
    }

    //变成循环财神密卷，从第二期开始
    public static int getSecretVolumeNo(int no){
        List<Integer> dateList = StringUtils.stringToIntegerList(GameConfig.SECRET_VOLUME_DATE,";");
        if(dateList.size() >= no){
            return no;
        }
        return 2;
    }


    //返回从第一期开始到现在应该到达的期数
    //假如已经过了最后一期了已经配置没有但是时间已经到了也不会变化了，一直停留在当前期
    //lastLoginTime 用来判断策划是不是忘了配置这个活动了，判断是不是玩家登录时间是否在重置档期内_(:з」∠)_
    public static List<Integer> getUserNowNoDay(UserSecretVolume userSecretVolume,long lastLoginTime) {
        List<Integer> res = new ArrayList<>();
        List<Integer> dateList = StringUtils.stringToIntegerList(GameConfig.SECRET_VOLUME_DATE,";");
        int nowNo = userSecretVolume.getNo();
        int allDay = 0;
        int changeNo = nowNo;//应该到达的期数
        int changeDay = 0;//接上一个期数过去的总天数
        for(int i=nowNo;i<=dateList.size();i++){
            allDay += dateList.get(i-1);
            if(System.currentTimeMillis() <= userSecretVolume.getStartDate() + (long)allDay*24*60*60*1000){
                changeNo = i;
                break;
            }
            changeDay = allDay;
        }

        res.add(0,changeNo);
        res.add(1,changeNo==nowNo?0:changeDay);//假如后面没有配置了就是0
        return res;
    }

    public static void main(String[] args){
        UserSecretVolume userSecretVolume = new UserSecretVolume();
        userSecretVolume.setStartDate(1596988800000L);
        userSecretVolume.setNo(1);
        System.err.println(getUserNowNoDay(userSecretVolume,0));
    }
}
